package com.cardbaobao.cardbabyclient.controller;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.cardbaobao.cardbabyclient.ui.activity.CreditDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.LoansDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.web.EventWebViewActivity;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.model.Banner;
import com.cardbaobao.cardbabyclient.model.HeadCommon;

import java.util.Map;

/**
 * Created by Jiangzx on 2017/6/29 10:37.
 */

public class CommonJumpController {
    private Context context;

    public static String FROM_PAGE="fromPage";

    public CommonJumpController(Context context){
        this.context=context;
    }

    /**banner图跳转*/
    public void bannerJump(Banner.CarouselFigureListBean bean, Map<String,Object> extra){
        Intent intent=new Intent();
        if(bean.getPage_type()== Constant.TYPE_NATIVE){
            String detailId=bean.getDetail_id();
            String detailName=bean.getDetail_name();
            //id和name都不为空时才进行跳转
            if(!TextUtils.isEmpty(detailId)&&!TextUtils.isEmpty(detailName)){
                String pageType=bean.getDetail_code();
                switch (pageType){
                    case Constant.PAGE_ZCC0101:
                        //跳到信用卡详情页
                        intent.setClass(context, CreditDetailActivity.class);
                        intent.putExtra(CreditDetailActivity.CARD_ID_S,bean.getDetail_id());
                        intent.putExtra(CreditDetailActivity.CARD_NAME_S,bean.getDetail_name());
                        intent.putExtra(FROM_PAGE, (String) extra.get(FROM_PAGE));
                        context.startActivity(intent);
                        break;
                    case Constant.PAGE_ZCC0102:
                        intent.setClass(context, LoansDetailActivity.class);
                        intent.putExtra(LoansDetailActivity.LOANS_ID_S,bean.getDetail_id());
                        intent.putExtra(LoansDetailActivity.LOANS_NAME_S,bean.getDetail_name());
                        intent.putExtra(FROM_PAGE, (String) extra.get(FROM_PAGE));
                        context.startActivity(intent);
                        break;
                }
            }
        }else{
            h5WebJump(bean.getPage_type(),
                        bean.getUrl(),
                        bean.getTopical(),
                        extra);
        }
    }

    /**跑马灯跳转*/
    public void marqueeJump(HeadCommon.MarqueeListBean bean,Map<String,Object> extra){
        Intent intent=new Intent();
        if(bean.getPage_type()== Constant.TYPE_NATIVE){
            String detailId=bean.getDetail_id();
            String detailName=bean.getDetail_name();
            //id和name都不为空时才进行跳转
            if(!TextUtils.isEmpty(detailId)&&!TextUtils.isEmpty(detailName)){
                String pageType=bean.getDetail_code();
                switch (pageType){
                    case Constant.PAGE_ZCC0101:
                        //跳到信用卡详情页
                        intent.setClass(context, CreditDetailActivity.class);
                        intent.putExtra(CreditDetailActivity.CARD_ID_S,bean.getDetail_id());
                        intent.putExtra(CreditDetailActivity.CARD_NAME_S,bean.getDetail_name());
                        intent.putExtra(FROM_PAGE, (String) extra.get(FROM_PAGE));
                        context.startActivity(intent);
                        break;
                    case Constant.PAGE_ZCC0102:
                        intent.setClass(context, LoansDetailActivity.class);
                        intent.putExtra(LoansDetailActivity.LOANS_ID_S,bean.getDetail_id());
                        intent.putExtra(LoansDetailActivity.LOANS_NAME_S,bean.getDetail_name());
                        intent.putExtra(FROM_PAGE, (String) extra.get(FROM_PAGE));
                        context.startActivity(intent);
                        break;
                }
            }
        }else{
            h5WebJump(bean.getPage_type(),bean.getUrl(),bean.getDetail_name(),extra);
        }
    }

    /**原生详情页面跳转*/
    public void nativeDetailJump(String detailCode,String cardId,String cardName,Map<String,Object> extra){
        if(!TextUtils.isEmpty(cardId)&&!TextUtils.isEmpty(cardName)){
            Intent intent=new Intent();
            switch (detailCode){
                case Constant.PAGE_ZCC0101:
                    //信用卡详情
                    intent.setClass(context,CreditDetailActivity.class);
                    intent.putExtra(CreditDetailActivity.CARD_ID_S,cardId);
                    intent.putExtra(CreditDetailActivity.CARD_NAME_S,cardName);
                    context.startActivity(intent);
                    break;
                case Constant.PAGE_ZCC0102:
                    //贷款详情
                    intent.setClass(context,LoansDetailActivity.class);
                    intent.putExtra(LoansDetailActivity.LOANS_ID_S,cardId);
                    intent.putExtra(LoansDetailActivity.LOANS_NAME_S,cardName);
                    context.startActivity(intent);
                    break;
            }
        }
    }

    /**web页面跳转*/
    public void h5WebJump(int pageType,String webUrl,String webTitle,Map<String,Object> extra){
        if(!TextUtils.isEmpty(webUrl)){
            Intent intent=new Intent(context,EventWebViewActivity.class);
            intent.putExtra(EventWebViewActivity.WEB_URL_S,webUrl);
            intent.putExtra(EventWebViewActivity.WEB_TITLE_S,webTitle);
            if(extra!=null){
                intent.putExtra(EventWebViewActivity.WEB_TYPE_I,
                        (Integer) extra.get(EventWebViewActivity.WEB_TYPE_I));
            }
            context.startActivity(intent);
        }
    }
}
